<?php
use com\gdl\common\dataobject\common\ResultDO; 
use com\gdl\newagk\interfaces\UserServiceIf;
use com\gdl\newagk\dataobject\user\UserRequestDTO; 
use com\gdl\newagk\dataobject\user\UserLoginRequestDTO; 
use com\gdl\newagk\dataobject\user\UserPasswordRequestDTO; 
use com\gdl\newagk\dataobject\user\RePasswordRequestDTO;
use com\gdl\newagk\dataobject\user\RegisterRequestDTO;
use com\gdl\newagk\dataobject\user\UserDTO;
require(dirname(dirname(__FILE__)) ."/php_sdk-master/include.php");
use MagicCrypt\MagicCrypt;
/**
 * App用户相关接口 
 * 此接口实际实现为ActionService接口
 */
class api_UserService extends api_Abstract implements UserServiceIf{
	
	static public $photo = "http://ot7pftuwd.bkt.clouddn.com/jgg8s6pc_264rfqm9vgty5ae187f645c25.jpg";
    /**
     * 用户名密码登录
     * 此接口实际实现为ActionService接口
     */
    public function appUserLogin(UserLoginRequestDTO $user)
    { 
        $username = $user->username ? gdl_lib_BaseUtils::getStr($user->username) : "";
        $password = $user->password ? gdl_lib_BaseUtils::getStr($user->password) : "";
        $platform =  $user->platform ? gdl_lib_BaseUtils::getStr($user->platform, 'int') : 0;
	$result = new ResultDO();
        $result->success = false;
        $result->code = 0; 
        $result->data = []; 
        try{
                $result->success = true;
                return $result;
        } catch (Exception $e) {
                $result->success = false;
                $result->code = $e->getCode();
                $result->message = $e->getMessage(); 
        }
        return $result; 
    }
    /**
     *  发送手机验证码
     */
    public function appUserCode(UserPasswordRequestDTO $user){ 
	$result = new ResultDO();
        $result->code = 400;
        $result->success = true;
        $result->data[] = [];
        # cdoe = login登录 code = repassword重置密码  code = reg注册 code = all其他 code = editphone
        $phone = $user->phone ? gdl_lib_BaseUtils::getStr($user->phone) : ""; 
        $type = $user->code ?  gdl_lib_BaseUtils::getStr($user->code) : "";
		$gdl_userid = $user->userid ?  gdl_lib_BaseUtils::getStr($user->userid) : "";
        try{
			$modelMember = new model_agkuc_ucentermember();
			
            # 查询uc里是否绑定了该用户
            $condition['mobile'] = $phone;
			//$condition['status'] = 1;
            $user = $modelMember->selectOne($condition,'id,userName,trueName');
            # uc里已有用户
            if(!$user['id'] && $type!="reg" && $type!="repassword" && $type!="all" && $type!="editphone"){
                $result->message = '您还没有绑定该手机号';
                return $result;
            }
			
			# 被注册的和被绑定的号码不允许再绑定
			if($type=="editphone" || $type=="reg"){
				if($user['id']){
					$result->message = "手机号码已绑定，请勿重新绑定";
					return $result;
				}
			}
			
            # 发送验证码存入数据库
            $usercode = new model_newagk_verifycode();
            $expiration = time()+300;
            $create_time = time();
            $code = mt_rand('100000','999999');
            $userid = $user['id']?$user['id']:0;
            
			$usercode->delete("mobile='{$phone}'"); # 发送验证码之前，先将该号码所有的验证码删了
			
            $usercodeEnd = $usercode->selectOne("mobile='{$phone}'",'userId');
            if(empty($usercodeEnd['userId'])){
                    $insert = array(
                            'userId' => $userid,
                            'mobile' => $phone,
                            'code' => $code,
                            'expireTime' => $expiration,
                            'createTime' => $create_time,
                            'status' => 1,
                    );
					# 修改手机号码
					if($type == "editphone"){
						$insert['userId'] = $gdl_userid;
					}
                    $usercode->insert($insert, true);
            } else { 
                 //
            }
            
            # 发送验证码短信
            $encryptObj = new MagicCrypt();
            if($type=="login"){
                $strCode = "【安管控】您正在登录该账号，验证码：".$code.",有效期5分钟";
            }else if($type=="repassword"){
                $strCode = "【安管控】您正在重置密码，验证码：".$code.",有效期5分钟";
            }else if($type=="reg"){
                $strCode = "【安管控】您正在注册安管控，验证码：".$code.",有效期5分钟";
            }else{
                $strCode = "【安管控】您的验证码是：".$code.",有效期5分钟";
            }

			# 修改手机号码
            $smsend = $encryptObj->SendSMSEnd($phone,$strCode);
            $result->message = $smsend->result;
            if($smsend->result!="SUCCESS"){
                $result->message = "发送验证码失败，请重新获取";
                return $result;
            }
            $result->code = 200;
            $result->success = true; 
            $userid = $userid?$userid:0; # 其他类型用户id为零
			if($type == "editphone"){
				$result->data[] = ['userid'=>$gdl_userid,'phone'=>$phone];
			}else{
				$result->data[] = ['userid'=>$userid,'phone'=>$phone];
			}
        } catch (Exception $e) {
            $result->success = false;
            $result->code = $e->getCode();
            $result->message = $e->getMessage(); 
        }
        return $result;
    }
    /**
     *  手机验证码登录
     */
    public function appUserNameLogin(UserPasswordRequestDTO $user){
        $result = new ResultDO();
        $result->code = 400;
        $result->success = true;
        $result->data[] = [];
        
        $phone = $user->phone ? gdl_lib_BaseUtils::getStr($user->phone) : ""; 
        $code = $user->code ?  gdl_lib_BaseUtils::getStr($user->code) : "";
        $userid = $user->userid ?gdl_lib_BaseUtils::getStr($user->userid) : "";
        //var_dump(self::$photo);exit;
        try{
            # 查询验证码数据是否有该验证码
            $usercode = new model_newagk_verifycode();
            $usercodeEnd = $usercode->selectOne("status=1 and mobile='{$phone}' and userId='{$userid}'",'code,expireTime'); 
            if(empty($usercodeEnd['code'])){
                $result->message = '验证失败，验证码不存在';
            } else {
                if($usercodeEnd['code']!=$code){ 
                    $result->message = '验证码错误';
                }
                if($usercodeEnd['expireTime']<time()){ 
                    $result->message = '验证码,已过期';
                }
            }
            # 验证成功 查询用户信息
            if(empty($result->message)){
                $modelMember = new model_agkuc_ucentermember();
                $condition['mobile'] = $phone;
                $condition['id'] = $userid;
                $user = $modelMember->selectOne($condition);
				
				# 查user
				$userModel = new model_newagk_user();
				$useridinfo = $userModel->selectOne("gdlUserid='{$user['id']}' and isdelete=0","userId,photo,isdelete,status");
				#已被删除
				if(empty($useridinfo)){
					$result->message = "用户已被删除";
					return $result;
				}
				#已被禁用
				if($useridinfo['status']!=1 && $useridinfo['isdelete']=0){
					$result->message = "用户已被禁用，请联系平台管理员开启";
					return $result;
				}
				
                # 再查newagk 里的user_companyid
                $userCompany = new model_newagk_usercompany();
                $userCompanyData = $userCompany->selectOne("userId='{$useridinfo['userId']}' and defaultPlaform=1 and status=1 and isdelete=0","id,userId,platformId,companyId"); # 查询上次选择的平台 default_platform =1
				
                $identity_id = isset($userCompanyData['id'])?$userCompanyData['id'] : 0;
                $platform_id = isset($userCompanyData['platformId'])?$userCompanyData['platformId'] : 0;
                $company_id = isset($userCompanyData['companyId'])?$userCompanyData['companyId'] : 0;
                $usercode->delete("mobile='{$phone}'");
                $userLogo = $useridinfo['photo'] ? $useridinfo['photo'] : self::$photo;
				# 统计有几个平台
				$p_leftJoin = array('agk_user_company as uc' => 'agk_platform.id=uc.platformId');
				$p_condition['uc.userId'] = $useridinfo['userId'];
				$p_condition['agk_platform.status'] = 1;
				$p_condition['uc.isdelete'] = 0;
				$p_items = 'agk_platform.id,agk_platform.parentid,agk_platform.`reals`,uc.id as indetity_id,agk_platform.adminRealname';
				$p_groupBy = 'group by agk_platform.id';
				$modelPlaform = new model_newagk_platform();
                $platformRes = $modelPlaform->select($p_condition, $p_items, $p_groupBy, '', $p_leftJoin)->items;
				$platformCount = !empty($platformRes) ? count($platformRes) : 0;
				
				$platformName = "";
				foreach($platformRes as $key){
					if($key['id']==$platform_id && $platform_id!=0){
						$platformName = $key['adminRealname'];
					}
				}
				
                $result->data[] = ['username' => $user['userName'],'truename'=>$user['trueName'],'userid'=>$useridinfo['userId'],'gdl_userid'=> $user['id'],'idcard' => $user['idcard'],'photo'=>$userLogo,'phone'=>$user['mobile'],
                     'identity_id'=>$identity_id,'platform_id'=>$platform_id,'company_id'=>$company_id,'platformCount'=>$platformCount,'platformName'=>$platformName];
                $result->message = "验证成功";
                $result->code = 200;
                $result->success = true;
            }
        }catch(Exception $e){
            $result->success = false;
            $result->code = $e->getCode();
            $result->message = $e->getMessage(); 
        }
        return $result;
    }
    /**
     *  忘记密码 修改密码
     */
    public function appUserPassword(RePasswordRequestDTO $user){
        $result = new ResultDO();
        $result->code = 400;
        $result->success = true;
        $result->data[] = [];
        # 存在一个bug 抓包直接绕开验证码更具userid修改密码
        $phone = $user->phone ? gdl_lib_BaseUtils::getStr($user->phone) : ""; 
        $code = $user->code ? gdl_lib_BaseUtils::getStr($user->code) : ""; 
        $password = $user->password ? gdl_lib_BaseUtils::getStr($user->password) : ""; 
        $repassword = $user->repassword ? gdl_lib_BaseUtils::getStr($user->repassword) : ""; 
        $userid = $user->userid ? gdl_lib_BaseUtils::getStr($user->userid) : "";
        
        if($password!=$repassword){
            $result->message = "两次密码不一致";
            return $result;
        }
        
        try{
            # 查询验证码数据是否有该验证码
            $usercode = new model_newagk_verifycode();
            $usercodeEnd = $usercode->selectOne("status=1 and mobile='{$phone}' and userId='{$userid}'",'code,expireTime');
            if(empty($usercodeEnd['code'])){
                $result->message = '验证失败，验证码不存在';
            } else {
                if($usercodeEnd['code']!=$code){ 
                    $result->message = '验证码错误';
                }
                if($usercodeEnd['expireTime']<time()){ 
                    $result->message = '验证码,已过期';
                }
            }
            
            $modelMember = new model_agkuc_ucentermember();
            $condition['id'] = $userid;
            $user = $modelMember->selectOne($condition);
            $password_new = md5((md5(md5($password))) . $user['passsalt']);
            $rs = $modelMember->update(['id' => $user['id']],['password' => $password_new]);
            if($rs){
                $result->code = 200;
                $result->data[] = ['username' => $user['userName'],'truename'=>$user['trueName'],'userid'=> $user['id'],'idcard' => $user['idcard'],'photo'=>self::$photo,'phone'=>$user['mobile']];
                $result->message = '修改成功,请重新登录';
            }else{
                $result->message = '修改失败，新密码与旧密码相同';
            }
            
        }catch(Exception $e){
            $result->success = false;
            $result->code = $e->getCode();
            $result->message = $e->getMessage(); 
        }
        
        return $result;
    }
    /**
     * 安管控app注册
     */
    public function registerUser(RegisterRequestDTO $RegisterDO){
        try {
            $resultDO = new ResultDO();
            $resultDO->data[] = [];
            $resultDO->code = 400;
            $resultDO->success = TRUE;
            $username = $RegisterDO->username ? gdl_lib_BaseUtils::getStr($RegisterDO->username, 'string') : '';
            $password = $RegisterDO->password ? gdl_lib_BaseUtils::getStr($RegisterDO->password, 'string') : '';
            $truename = $RegisterDO->truename ? gdl_lib_BaseUtils::getStr($RegisterDO->truename, 'string') : '';
            $mobile = $RegisterDO->mobile ? gdl_lib_BaseUtils::getStr($RegisterDO->mobile, 'string') : '';
            $idcard = $RegisterDO->idcard ? gdl_lib_BaseUtils::getStr($RegisterDO->idcard, 'string') : '';
            $email = $RegisterDO->email ? gdl_lib_BaseUtils::getStr($RegisterDO->email, 'string') : '';
            $way = $RegisterDO->way ? gdl_lib_BaseUtils::getStr($RegisterDO->way, 'string') : '';
            $account_type = $RegisterDO->account_type ? gdl_lib_BaseUtils::getStr($RegisterDO->account_type,'string') : 1;
            $code = $RegisterDO->code ? gdl_lib_BaseUtils::getStr($RegisterDO->code, 'string') : '';
            $modelUcenterMember = new model_agkuc_ucentermember();
            
            if(empty($password)||strlen($password)<6){
				$resultDO->success = TRUE;
				$resultDO->code = 400;
				$resultDO->message = '请输入6位登录密码';
				return $resultDO;
			}
            //检查是否存在相同用户
            if ($idcard) {
                $existWhere = ['idcard' => $idcard];
                $existRes = $modelUcenterMember->selectOne($existWhere, 'id');
                if ($existRes['id']) {
                    $resultDO->success = TRUE;
                    $resultDO->code = 400;
                    $resultDO->message = '注册失败，身份证已存在';
                    return $resultDO;
                }
                
            }

            if ($mobile) {
                $existWhere = ['mobile' => $mobile];
                $existRes = $modelUcenterMember->selectOne($existWhere, 'id');
                if ($existRes['id']) {
                    $resultDO->success = TRUE;
                    $resultDO->code = 400;
                    $resultDO->message = '注册失败，手机号码已存在';
                    return $resultDO;
                } 
            }
            //判断验证码
            if(!$code){
                $resultDO->success = TRUE;
                $resultDO->code = 400;
                $resultDO->message = '请输入6位验证码';
                return $resultDO;
            }
            # 查询验证码数据是否有该验证码
            $usercode = new model_newagk_verifycode();
            $usercodeEnd = $usercode->selectOne("status=1 and mobile='{$mobile}' and userId=0",'code,expireTime');
            if(empty($usercodeEnd['code'])){
                $resultDO->message = '验证失败，验证码不存在';
                return $resultDO;
            } else {
                if($usercodeEnd['code']!=$code){ 
                    $resultDO->message = '验证码错误';
                    return $resultDO;
                }
                if($usercodeEnd['expireTime']<time()){ 
                    $resultDO->message = '验证码,已过期';
                    return $resultDO;
                }
            } 
		  
                //注册
                $insert = [];
                $insert['username'] = $username.mt_rand(1000, 9999);
                $insert['truename'] = $truename;
                $insert['passsalt'] = parent::random(8);
                $insert['password'] = parent::dpassword($password, $insert['passsalt']);
				$insert['showpassword'] = $password;
                $insert['email'] = $email;
                $insert['mobile'] = $mobile;
                $insert['idcard'] = $idcard;
                $insert['reg_time'] = time();
                $insert['status'] = 1;
                $insert['type'] = 1;
                $insert['way'] = $way;
                $insert['account_type'] = $account_type;
                $ret = $modelUcenterMember->insert($insert);
                if ($ret) {
					
                    $modelMember = new model_agkuc_member();
                    $inserMember = [
						'uid'=>$ret,
                        'nickname' => $insert['username'],
                        'reg_time' => time(), 'status' => 1,
                        'last_login_role' => 1,
                        'show_role' => 1,
                    ];
                    $retMember = $modelMember->insert($inserMember);
					
					# 继续往agk_user注册
					$userModle = new model_newagk_user(); 
					$UserList = $userModle->selectOne(['gdlUserId'=>$ret,'isdelete'=>0],"userId,mobile");
					$userret = $UserList['userId'];
					$idcarinfo = $this->getIdcard($insert['idcard']);
					if(empty($UserList['userId'])){
						# 插入到user
						$userInsert = [
							'gdlUserId' => $ret,
							'userName' => $insert['username'],
							'realName' => $insert['truename'],
							'idcard' => $insert['idcard'],
							'mobile' => $insert['mobile'],
							'createTime'=>time(),
							'isdelete'=>0,
							'status'=>1,
							'birthday'=>$idcarinfo['birth'],
							'sex'=>$idcarinfo['sex'], # 0:男 1 女
							'city'=>"未获取",
							'county'=>"未获取",
							'age'=>$idcarinfo['age'],
							//'admin_reg'=>$re['admin_reg'],#这个admin_reg不能作为唯一依据
						];
						$userret = $userModle->insert($userInsert);
					} 
					
                    if ($userret) {
                        # 验证成功修改验证码过期
                        $usercode->delete("mobile='{$mobile}'");
                        $resUserlist = $modelUcenterMember->selectOne("id='{$ret}'"); 
						
                        $resultDO->success = TRUE;
                        $resultDO->code = 200;
                        $resultDO->message = '注册成功'; 
                        $resultDO->data[] = ['username' => $resUserlist['username'],'truename'=>$resUserlist['truename'],'userid'=> $resUserlist['id'],'idcard' => $resUserlist['idcard'],'photo'=>self::$photo,'phone'=>$resUserlist['mobile']];
                    } else {
                        $resultDO->success = TRUE;
                        $resultDO->code = 400;
                        $resultDO->message = $modelMember->getError();
                    }
                } else {
                    $resultDO->success = TRUE;
                    $resultDO->code = 400;
                    $resultDO->message = $modelUcenterMember->getError();
                }
			 
        } catch (Exception $ex) {
            $resultDO->success = FALSE;
            $resultDO->code = 500;
            $resultDO->message = $ex->getMessage();
        }
        return $resultDO;
    }
    /**
     *  上传头像
     */
    public function appAddLogo(UserDTO $user){
        $resultDO = new ResultDO();
        $resultDO->data[] = [];
        $resultDO->code = 200;
        $resultDO->success = TRUE;
		$resultDO->message = "修改失败";
		return $resultDO;
    }
    
    /**
     *  手机app修改用户资料
     */
    public function appEditUser(UserDTO $user){
        $resultDO = new ResultDO();
		$resultDO->data[] = [];
		$resultDO->code = 400;
		$resultDO->success = TRUE;
		$resultDO->message = "修改失败";
		# 需要更新的数据
		$data = $user->data ? $user->data : '';
		$platformId = $user->id ? gdl_lib_BaseUtils::getStr($user->id, 'int') : '';
		$userid = $user->userid ? gdl_lib_BaseUtils::getStr($user->userid, 'int') : '';
		$gdl_userid = $user->gdl_userid ? gdl_lib_BaseUtils::getStr($user->gdl_userid, 'int') : '';
		$identity_id = $user->identity_id ? gdl_lib_BaseUtils::getStr($user->identity_id, 'int') : '';
		
		# 需要用到的model
		$userModel = new model_newagk_user();
		$userCompanyModel = new model_newagk_usercompany();
		$ucMberModel = new model_agkuc_member();
		$ucUserMberModel = new model_agkuc_ucentermember();
		
		try{
			# 修改真实姓名
			if($data['truename']){
				$ucUserMberData = ['truename'=>$data['truename']];
				$userData = ['realName'=>$data['truename']];
				$ucRet = $ucUserMberModel->update(['id'=>$gdl_userid],$ucUserMberData);
				$userRet = $userModel->update(['gdlUserid'=>$gdl_userid],$userData);
				if($ucRet && $userRet){
					$resultDO->code = 200;
					$resultDO->message = "修改成功姓名成功";
				}
			}
			# 修改账号
			if($data['username']){
				$ucUserMberData = ['username'=>$data['username']];
				$isUcMberIsset = $ucUserMberModel->selectOne(['username'=>$data['username']],'id,username,idcard');
				if($isUcMberIsset['id']){
					$resultDO->message = "该账号已存在，请重新输入";
					return $resultDO;
				}
				$ucMberData = ['nickname'=>$data['username']];
				$userData = ['userName'=>$data['username']];
				
				$ucUserMberRet = $ucUserMberModel->update(['id'=>$gdl_userid],$ucUserMberData);
				$ucMberRet = $ucMberModel->update(['uid'=>$gdl_userid],$ucMberData);
				$userRet = $userModel->update(['gdlUserid'=>$gdl_userid],$userData);
				if($ucMberRet || $ucMberRet || $userRet){
					$resultDO->code = 200;
					$resultDO->message = "修改成功账号成功";
				}
			}
			
			# 修改身份证
			if($data['idcard']){
				$ucUserMberData = ['idcard'=>$data['idcard']];
				$isUcMberIsset = $ucUserMberModel->selectOne(['idcard'=>$data['idcard']],'id,username,idcard');
				if($isUcMberIsset['id']){
					$resultDO->message = "修改失败，该身份证号已存在";
					return $resultDO;
				}
				$userData = ['idcard'=>$data['idcard']];
				$ucUserMberRet = $ucUserMberModel->update(['id'=>$gdl_userid],$ucUserMberData);
				$userRet = $userModel->update(['gdlUserid'=>$gdl_userid],$userData);
				if($ucUserMberRet || $userRet){
					$resultDO->code = 200;
					$resultDO->message = "修改身份证成功";
				}
			} 	
		}catch(Exception $ex){
			$resultDO->success = FALSE;
            $resultDO->code = 500;
            $resultDO->message = $ex->getMessage();
		}
		return $resultDO;
    }
	
	/**
     *  修改手机号码
     */
    public function appEditPhone(UserDTO $user){
		$result = new ResultDO();
        $result->code = 400;
        $result->success = true;
        $result->data[] = [];
        # 存在一个bug 抓包直接绕开验证码更具userid修改密码
        $phone = $user->phone ? gdl_lib_BaseUtils::getStr($user->phone) : ""; 
        $code = $user->code ? gdl_lib_BaseUtils::getStr($user->code) : ""; 
		$userid = $user->userid ? gdl_lib_BaseUtils::getStr($user->userid) : "";  # 实际为gdl_userid
		
		if(empty($phone) || empty($code) || empty($userid)){
			$result->message = "缺少必要参数";
			return $result;
		}
		
		try{
			# 查询验证码数据是否有该验证码
            $usercode = new model_newagk_verifycode();
            $usercodeEnd = $usercode->selectOne("status=1 and mobile='{$phone}' and userId='{$userid}'",'code,expireTime');
			
            if(empty($usercodeEnd['code'])){
                $result->message = '验证失败，验证码不存在';
            } else {
                if($usercodeEnd['code']!=$code){ 
                    $result->message = '验证码错误';
                }
                if($usercodeEnd['expireTime']<time()){ 
                    $result->message = '验证码,已过期';
                }
            }
			
			# 修改uc 和user
			if(empty($result->message)){
				$ucMberModel = new model_agkuc_ucentermember();
				$userModel = new model_newagk_user();
				
				$ucData = ['mobile'=>$phone];
				$userData = ['mobile'=>$phone]; 
				
				if($ucMberModel->update(['id'=>$userid],$ucData)){
					$userRet = $userModel->update("gdlUserid=".$userid." and isdelete=0",$userData);
					$usercode->delete("mobile='{$phone}'");
					$result->message = "修改成功";
					$result->code = 200;
				}else{
					$result->message = "修改失败";
				}
			}
			
		}catch(Exception $ex){
			$resultDO->success = FALSE;
            $resultDO->code = 500;
            $resultDO->message = $ex->getMessage();
		}
        return $result;
    } 
	/**
     *  根据旧密码修改
     */
    public function appEditPassword(UserDTO $user){
        $result = new ResultDO();
        $result->code = 400;
        $result->success = true;
        $result->data[] = [];
        # 存在一个bug 抓包直接绕开验证码更具userid修改密码
        $data = $user->data ? $user->data: ""; 
		$gdl_userid = $user->userid ? gdl_lib_BaseUtils::getStr($user->userid) : "";  # 实际为gdl_userid
		
		$oldpassword = $data['oldpassword'] ? $data['oldpassword'] : "";
		$password = $data['password'] ? $data['password'] : "";
		$repassword = $data['repassword'] ? $data['repassword'] : "";
		if(empty($data) || empty($gdl_userid)){
			$result->message = "缺少必要参数";
			return $result;
		}
		
		try{
			$modelMember = new model_agkuc_ucentermember();
			$condition['id'] = $gdl_userid;
            $user = $modelMember->selectOne($condition);
			if($user['id']){
				if ($user['passsalt'] == 'aa123456') { 
                    $j_password = $oldpassword === '' ? '' : md5(sha1($oldpassword) . '*]f)={.zRuS;FZWUv6"TGJPO_5g<Kx#~k&|7nj(I');
                } else {
					var_dump("13456");
                    $j_password = md5((gdl_lib_BaseUtils::IsMd5($oldpassword) ? md5($oldpassword) : md5(md5($oldpassword))) . $user['passsalt']);
                }
				# 验证旧密码是否正确
				if($j_password == $user['password']) {
					$update = [
						'password'=>md5((md5(md5($password))).$user['passsalt']),
					];
					$ret = $modelMember->update(['id'=>$gdl_userid], $update);
					if($ret){
						$result->message = "修改密码成功，请重新登录";
						$result->code= 200;
					}else{
						$result->message = "修改失败，新密码不能与旧密码相同";
					}
				}else{
					$result->message = "旧密码不正确，请重新输入密码";
				}
			}else{
				$result->message = "用户不存在，修改失败";
			}
			
		}catch(Exception $ex){
			$resultDO->success = FALSE;
            $resultDO->code = 500;
            $resultDO->message = $ex->getMessage();
		}
		
		return $result;
    }
	/**
     *  退出平台 逻辑假删user_company
     */
    public function appExitPlaform(UserDTO $user){
		$resultDO = new ResultDO();
		$resultDO->data[] = [];
		$resultDO->code = 400;
		$resultDO->success = TRUE;
		
		$identity_id = $user->identity_id ? gdl_lib_BaseUtils::getStr($user->identity_id, 'int') : '';
		$platformId = $user->id ? gdl_lib_BaseUtils::getStr($user->id, 'int') : '';
		if(empty($identity_id) || empty($platformId)){
			$resultDO->message = "退出失败,缺少必要参数";
			return $resultDO;
		}
		
		try{
			
			$userCompanyModel = new model_newagk_usercompany();
			$data['isdelete'] = 1;
			$deleteCompany = $userCompanyModel->update(['id'=>$identity_id,'platformId'=>$platformId], $data);
			if($deleteCompany){
				$resultDO->message = "您已退出该平台";
				$resultDO->code = 200;
			}
			
		}catch(Exception $ex){
			$resultDO->success = FALSE;
            $resultDO->code = 500;
            $resultDO->message = $ex->getMessage();
		}
		
        return $resultDO;
    }
	
    /**
     *  用户详情
     */
    public function appUserInfo(UserRequestDTO $user){
        return "";
    }
	/**
		根据身份证获取信息
	*/
	public function getIdcard($idcard){
		//通过身份证号查询出性别与生日 
		$strleng = strlen($idcard);
		$birth = strlen($idcard)==15 ? ('19' . substr($idcard, 6, 6)) : substr($idcard, 6, 8); 
		$getsex = substr($idcard, (strlen($idcard)==$strleng ? -2 : -1), 1) % 2 ? '1' : '0'; //1为男 2为女
		$births = substr($birth,0,4)."-".substr($birth,4,2)."-".substr($birth,6,2);
		$years = date("Y",time());
		$age = $years-substr($birth,0,4);
		$sex = 0;
		if($getsex==1){
			$sex = 0; //男
		}else{
			$sex = 1; //女
		}
		return ['birth'=>$births, 'sex'=>$sex,'age'=>$age];
	}
 
}
